﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.BUS;
using QuanLyThuVien.VO;

namespace QuanLyThuVien
{
    public partial class frmThayMatKhau : Form
    {
        public frmThayMatKhau()
        {
            InitializeComponent();
        }

        private void txtMatKhauCu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) &&
                !Char.IsLetter(e.KeyChar) &&
                !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtMatKhauMoi_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) &&
                !Char.IsLetter(e.KeyChar) &&
                !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) &&
                !Char.IsLetter(e.KeyChar) &&
                !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            busNguoiDung busNguoiDung = new busNguoiDung();

            NguoiDung NguoiDung = busNguoiDung.ChonNguoiDung(frmChinh.NguoiDung.TenNguoiDung);

            if (String.Compare(txtMatKhauCu.Text, NguoiDung.MatKhau) != 0)
            {
                lblLoi.Text = "Khong Dung Mat Khau";
                lblLoi.Visible = true;
                return;
            }

            if (String.Compare(txtMatKhauMoi.Text, "") == 0)
            {
                lblLoi.Text = "Chua nhap Mat Khau Moi";
                lblLoi.Visible = true;
                return;
            }

            if (String.Compare(txtMatKhauMoi.Text, txtXacNhanMatKhau.Text) != 0)
            {
                lblLoi.Text = "Xac nhan mat khau khong dung";
                lblLoi.Visible = true;
                return;
            }

            busNguoiDung.ThayMatKhau(frmChinh.NguoiDung.TenNguoiDung, txtMatKhauMoi.Text);
            this.Close();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
